﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sasc.PV.DAL;
using Sasc.PV.BLL;

namespace Sasc.PV.Web.Admin.SystemManage
{
    public partial class BuMenInfoModify : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                ERPBuMen MyBuMen = new ERPBuMen();
                MyBuMen = MyBuMen.GetModel(int.Parse(Request.QueryString["ID"].ToString()));
                this.TextBox1.Text = MyBuMen.BuMenName;
                this.TextBox2.Text = MyBuMen.ChargeMan;
                this.TextBox3.Text = MyBuMen.TelStr;
                this.TextBox4.Text = MyBuMen.ChuanZhen;
                this.TextBox5.Text = MyBuMen.BackInfo;
            }
        }
        //修改
        protected void SubmitImageButton_Click(object sender, ImageClickEventArgs e)
        {
            if (PublicMethod.IFExists("BuMenName", "ERPBuMen", int.Parse(Request.QueryString["ID"].ToString()), this.TextBox1.Text) == true)
            {
                ERPBuMen MyBuMen = new ERPBuMen();
                MyBuMen.ID = int.Parse(Request.QueryString["ID"].ToString());
                MyBuMen.BuMenName = this.TextBox1.Text;
                MyBuMen.ChargeMan = this.TextBox2.Text;
                MyBuMen.TelStr = this.TextBox3.Text;
                MyBuMen.ChuanZhen = this.TextBox4.Text;
                MyBuMen.BackInfo = this.TextBox5.Text;
                MyBuMen.DirID = int.Parse(Request.QueryString["DirID"].ToString());
                MyBuMen.Update();

                //写系统日志
                ERPRiZhi MyRiZhi = new ERPRiZhi();
                MyRiZhi.UserName = PublicMethod.GetSessionValue("UserName");
                MyRiZhi.DoSomething = "用户修改部门信息(" + this.TextBox1.Text + ")";
                MyRiZhi.IpStr = System.Web.HttpContext.Current.Request.UserHostAddress.ToString();
                MyRiZhi.Add();

                MessageBox.ShowAndRedirect(this, "部门信息修改成功！", "BuMenInfo.aspx?View=" + Request.QueryString["View"].ToString() + "&Type=" + Request.QueryString["Type"].ToString() + "&DirID=" + Request.QueryString["DirID"].ToString());
            }
            else
            {
                MessageBox.Show(this, "该部门已经存在，请更换名称！");
            }
        }
    }
}